<?
class Personal extends Module{
	function Personal($row){
		Module::Module($row);
		$this->check_login();
		
		switch( Url::get('cmd') )
		{
			case 'change_password':							
				require_once 'forms/ChangePassword.php';
				$this->add_form(new ChangePasswordForm);
				break;
			case 'edit_user':	
			default:								
				if(Url::get('action')=='success_edit_user'){
					require_once 'forms/Success.php';
					$this->add_form(new SuccessForm);
					break;
				}
				else{
					require_once 'forms/EditUser.php';
					$this->add_form(new EditUserForm);
					break;															
				}
				break;
		}	
	}
	
	function check_login()
	{
		if(!User::is_login())
		{
			AZLib::check_uri();	
			Url::redirect_url('?page=sign_in&href='.base64_encode(CGlobal::$query_string));
		}
	}					
}

class PersonalDB{
	static function get_user_information(){
		return DB::select('user','id='.User::$current->data['id']);
	}
	
	static function update_password($password){
		return DB::update('user',array('password'=>User::encode_password($password)),'id='.User::$current->data['id']);
	}
	
	static function update_user_information($array){
		User::getUser(User::$current->data['id'],1,true);		
		return DB::update('user',$array,'id='.User::$current->data['id']);
	}
}
?>
